package com.yimin.floatball

import android.content.Context
import android.util.AttributeSet
import android.util.Log
import android.view.ContextMenu
import android.view.GestureDetector
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View
import android.view.ViewParent
import androidx.constraintlayout.widget.ConstraintLayout
import com.yimin.floatball.databinding.GestureTestBinding

class GestureTestView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : ConstraintLayout(context,attrs), GestureDetector.OnGestureListener {

    private val binding: GestureTestBinding
    private val gestureDetector: GestureDetector


    init {
        binding = GestureTestBinding.inflate(LayoutInflater.from(context))
        addView(binding.root)

        gestureDetector = GestureDetector(context, this)
    }

    override fun onTouchEvent(event: MotionEvent?): Boolean {
        return gestureDetector.onTouchEvent(event!!);
    }

    override fun onDown(e: MotionEvent): Boolean {
        Log.d(TAG, "onDown: ")
        return true
    }

    override fun onShowPress(e: MotionEvent) {
        Log.d(TAG, "onShowPress: ")
    }

    override fun onSingleTapUp(e: MotionEvent): Boolean {
        Log.d(TAG, "onSingleTapUp: ")
        return true
    }

    override fun onScroll(
        e1: MotionEvent?,
        e2: MotionEvent,
        distanceX: Float,
        distanceY: Float
    ): Boolean {
        Log.d(TAG, "onScroll: ")
        return true
    }

    override fun onLongPress(e: MotionEvent) {
        Log.d(TAG, "onLongPress: ")
    }

    override fun onFling(
        e1: MotionEvent?,
        e2: MotionEvent,
        velocityX: Float,
        velocityY: Float
    ): Boolean {
        Log.d(TAG, "onFling: ")
        return true
    }

}